﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Paulius.CssEditor.BusinessLogicContracts;
using Paulius.CssEditor.Parser;
using System.Collections;

namespace Paulius.CssEditor.BusinessLogic.ChangeManager
{
    public class ChangeManagerWeb : IChangeManager
    {

        public string CalculateFontStyle(string code)
        {
            List<string> selectors = new List<string>();

            CSSParser parser = new CSSParser();
            CSSDocument css = parser.ParseText(code);
            foreach (Directive dir in css.Directives)
            {
                foreach (RuleSet ruleset in dir.RuleSets)
                {
                    if (ruleset.Selectors.Count > 0)
                    {
                        selectors.Add(ruleset.Selectors[0].ToString());
                        if (ruleset.Selectors.Count > 1)
                        {
                            bool start = true;
                            foreach (Selector s in ruleset.Selectors)
                            {
                                if (start)
                                {
                                    start = false;
                                    continue;
                                }

                                selectors.Add(s.ToString());

                            }
                        }
                    }
                }
               
            }
            string returnString = "";
            foreach (string s in selectors)
            {
                returnString = returnString + s + "CHANGED";
            }
            //return returnString;
            return "CHANGED";
        }

        public void DetectChanges()
        {
            throw new NotImplementedException();
        }

        public void ChangeFont()
        {
            throw new NotImplementedException();
        }

        public void SaveChanges()
        {
            throw new NotImplementedException();
        }

        public void GetHistory()
        {
            throw new NotImplementedException();
        }
    }
}
